import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { User } from '@/types/user.d';

export const useUserStore = defineStore(
  'cpUser',
  () => {
    const userInfo = ref({} as User);
    const setUserInfo = (userData: User) => {
      userInfo.value = userData;
    };
    const deleteUserInfo = () => {
      userInfo.value = {} as User;
    };

    // 测试
    const msgInfo = ref<string>('qwert');

    return { msgInfo, userInfo, setUserInfo, deleteUserInfo };
  },
  {
    // persist: true
    persist: {
      key: 'userInfoData', //存储的key
      paths: ['msgInfo'] //配置了就存储配置的，不配置就存储所有的
    }
  }
);
